(* vec2d.ml
 *
 * This file is part of camEngine
 * 
 * camEngine - A 3d motor for ocaml
 * Copyright (C) 2009 DAVY Guillaume <davyg2@gmail.com>
 *
 * camEngine is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * camEngine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with camEngine.  If not, see <http://www.gnu.org/licenses/>.
 *)


	
let sgn = function
	| x when x > 0. -> 1.
	| x -> -.1.;;

type t=float
class vec2d xi yi = object (self)
	val mutable x = xi
	val mutable y = yi
	
	method get_x = x
	
	method get_y = y
	
	method move (p:vec2d) =
		x <- p#get_x +. x;
		y <- p#get_y +. y;
	
	method scale (p:vec2d) =
		x <- p#get_x *. x;
		y <- p#get_y *. y;
	
	method rotate (p:vec2d) (a:t) =
		let r = sqrt ( (x -.p#get_x) *. (x -.p#get_x) +. (y -.p#get_y) *. (y -.p#get_y)) in
		let w=a +. acos ((x -.p#get_x) /. r) *. sgn (y -.p#get_y) in
		x <- r *. cos ( w ) +. p#get_x;
		y <- r *. sin ( w ) +. p#get_y;
	
	method resize (l:t) =
		x <- x *. l;
		y <- y *. l;
	
	method copy =
		new vec2d x y;
end;;

